package com.class04.cookie5;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassDescription:
 * 接受cookie
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/6 8:21
 */
@Controller
@ResponseBody
public class CookieController {
    @GetMapping("cookie/getCookie")
//    @CookieValue 注释将 HTTP Cookie 的值绑定到控制器中的方法参数。
    public String getCookie(@CookieValue("cookieName") String value){
        System.out.println("value = " + value);
        return value;
    }

    @GetMapping("cookie/saveCookie")
    public String saveCookie(HttpServletResponse response){
        Cookie cookie = new Cookie("cookieName", "xiaopangxiu");
         response.addCookie(cookie);
        return "saveCookie success";
    }
}
